<%@page import="com.honeycomb.utils.SystemConstants"%>
<%@page import="com.honeycomb.user.dto.UserinfoDto"%>
<%@page import="com.honeycomb.common.PositionInfo"%>
<%@page import="java.util.Stack"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<style type="text/css">

		.map_tb {
			width: 46px;
			height: 53px;
			text-align: center;
			background: url('../resource/images/map/map_tb_middle.png') no-repeat transparent;
		}
		
		.map_tb_img {
			width: 37px;
			height: 37px;
			margin-top: 3px;
		}
		
		.map_tb_articleMarker {
			width: 35px;
			height: 40px;
			text-align: center;
			background: url('../resource/images/map/map_tb_articleMarker_middle.png') no-repeat transparent;
		}
		
		.map_tb_articleMarker_coincide {
			width: 41px;
			height: 43px;
			text-align: center;
			background: url('../resource/images/map/map_tb_articlemarker_middle_coincide.png') no-repeat transparent;
		}
		
		.map_tb_img_articleMarker {
			width: 28px;
			height: 28px;
			margin-top: 2px;
			margin-left: 1px;
		}
		
		.map_tb_img_articleMarker_coincide {
			width: 28px;
			height: 28px;
			margin-top: 7px;
			margin-left: 3px;
		}
		
		.triangle-border { 
					    position:absolute; 
					    left:30px; 
					    overflow:hidden; 
					    width:0; 
					    height:0; 
					    border-width:10px; 
					    border-style:dashed dashed solid dashed; 
		}
		.tb-background { 
					    top:-20px; 
					    border-color:transparent transparent #c0c0c0 transparent; 
		}
		.tb-border { 
				    top:-19px; 
					border-color:transparent transparent #f3f3f3 transparent; 
		}
		
		.articleMessage-box {
			position:relative;   
			width:340px; 
			height:156px; 
			background:#FFFFFF; 
			/*box-shadow:1px 2px 3px #E9FBE4;*/
			box-shadow: -moz-box-shadow:1px 2px 3px #382C2C; -webkit-box-shadow:1px 2px 3px #382C2C; box-shadow:1px 2px 3px #382C2C; 
			border: 1px solid #CCC; 
			border-radius:4px; 
			color:#666666;
			/* background-image: -webkit-gradient(linear,0% 100%, 0% 0%, from(#FFFDFD), to(#FFADAD), color-stop(0.0,#FFFFFF)); */
			/* border-bottom: #ccc 1px solid; border-left: #ccc 1px solid; padding-bottom: 2px; padding-left: 2px; padding-right: 2px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; padding-top: 2px */
		}
		
		.articleMessage-box-pointer{
			margin: -2px 24px;
			width: 0;
			height: 0;
			border-left: 10px solid transparent;
			border-right: 10px solid transparent;
			border-top: 10px solid #FFFFFF;
		}
		
		.promitMarker {
			box-shadow: -moz-box-shadow:1px 2px 3px #382C2C; -webkit-box-shadow:1px 2px 3px #382C2C; box-shadow:1px 2px 3px #382C2C; 
			border: 1px solid #CCC; 
			border-radius:4px; 
			color:#666666;
			font-size: 13px;
			width: 200px; 
			height: 80px;
			overflow: hidden;
		}
		
		.promotMarker-buttom-pointer { 
			margin: -2px 30px;
			width: 0;
			height: 0;
			border-left: 7px solid transparent;
			border-right: 7px solid transparent;
			border-top: 12px solid #FFFFFF;
		}
		
/****************************************************************/
#myLocationMarkerContent 
{  
  width:40px;  
  height:40px;  
  border:2px solid blue;   /* 边框宽度为3px */
  background:blue;  
  position:relative;  
}  
#myLocationMarkerContent .sp1  
{  
  position:absolute; 
  left:14px; 
  overflow:hidden; 
  width:0; 
  height:0; 
  border-width:6px; 
  border-style:solid dashed dashed dashed;
  bottom:-14px; 
  border-color:blue transparent transparent transparent;
}  

/* #articleAuthorLogoMarkerContent
{  
  width:30px;  
  height:30px;  
  border:2px solid white;
  background:white;
  position:relative;  
} */  

.articleAuthorLogoMarkerContent .sp1  
{  
  position:absolute; 
  left:13px; 
  overflow:hidden; 
  width:0; 
  height:0; 
  border-width:8px; 
  border-style:solid dashed dashed dashed;
  bottom:-16px; 
  border-color: #AAAAAA transparent transparent transparent;
}  

/* 用户头像尖角DIV */
#myLocationMarkerContent  
{  
  width:40px;  
  height:40px;  
  border:2px solid blue;   /* 边框宽度为3px */  
  position:relative;  
}  
.jian_sp1,.jian_sp2  
{  
  position:absolute; 
  left:14px; 
  overflow:hidden; 
  width:0; 
  height:0; 
  border-width:6px; 
  border-style:solid dashed dashed dashed;
}  
.jian_sp1  
{  
  bottom:-14px; 
  border-color:blue transparent transparent transparent; 
}  
.jian_sp2  
{  
 bottom:-19px; 
 border-color: blue transparent transparent transparent;  
} 
	/* 消息头像尖角DIV */
		.articleAuthorLogoMarkerContent { 
					  width:37px;
					  height:37px;
					  position:relative;   
					  background:#ffffff; 
					  box-shadow:1px 2px 3px #E9FBE4; 
					  border:1px solid #c0c0c0; 
					  border-radius:4px; 
					  color:#000000; 
		}
		.jian_menu-triangle-border { 
					    position:absolute; 
					    left:13px; 
					    overflow:hidden; 
					    width:0; 
					    height:0; 
					    border-width:6px; 
					    border-style:solid dashed dashed dashed; 
		}
		
		.jian_menu-tb-background { 
					    bottom:-13px; 
					    border-color:#c0c0c0 transparent transparent transparent;
		}
		.jian_menu-tb-border { 
				    bottom:-12px; 
					border-color: #ffffff transparent transparent transparent; 
		}
</style>

	<%-- 地图区域 --%>
	   <%-- 信息区域 --%>
	   <div id="map_pos_info" style="box-shadow: -moz-box-shadow:1px 2px 3px #382C2C; -webkit-box-shadow:1px 2px 3px #382C2C; box-shadow:1px 2px 3px #382C2C; border-radius:5px; position: absolute; text-align: center; z-index:500; height: 30px; width: 410px; line-height: 30px; border: 1px solid #CCCCCC; background: #FFFFFF; display: none;">
						<input type="hidden" name="mapX" id="mapX"/>
						<input type="hidden" name="mapY" id="mapY"/>
						<input type="hidden" name="mapProvider" id="mapProvider" value="<%=getServletContext().getInitParameter("map_amap_id")%>"/>
						<span id="myAddr" style="float: left; display: block; width:67px; background: #AED4F5; color: #FFFFFF; border-radius:2px 0 0 2px; padding-left: 1px; cursor: pointer;" title="点击返回我的位置">
							<b>我的位置</b>
						</span>
						<span class="mapAddr" style="float: left; display: block; width:280px; background: #FFFFFF; overflow: hidden;"></span>
						<span style="float: left; display: block; width: 60px; height: 12px; line-height: 12px; margin-top: 15px;"><a href="javascript:searchAddr()" title="搜索想去的地方">换个地方</a></span>
						<span style="clear: both;"></span>
						
<!-- --------------------------------------------------------------------------------------------------- -->
						<!-- 搜索地点框 -->
						<div style="display: none; " id="search-input">
							<div id="search-cancel" style="float:left; text-align:center; line-height:30px; background:#FFFFFF; height: 30px; width: 67px; cursor: hand; cursor: pointer; text-align:center; color:#AED4F5; margin-left:2px;" title="点击返回我的位置">
								<b>我的位置</b>
							</div>
							<div style="float:left; width:70px; background:#FFFFFF; overflow:hidden; text-align:center; height: 28px; line-height:28px; border:1px solid #AED4F5; border-left:8px solid #AED4F5;">
								<input type="text" id="searchCity" style="height:28px; width:62px; border:0; border-style:none; line-height:28px;" />
							</div>
							
							<div style="float:left; width: 229px; background:#FFFFFF; height: 28px; line-height:28px; border:1px solid #AED4F5; border-right:0; overflow: hidden;">
								<input type="text" id="searchKeywords" style="height: 28px; width: 228px; border:0; border-style:none; line-height:28px;" />
								<div style="margin-left:-1px; height:auto !important; width:228px; background:#FFFFFF; border: 1px solid #AED4F5; border-top:-1px; border-top-color: #FFFFFF;" id="search-prompt"></div>
							</div>
							<div id="search-btn" style="float:left; text-align:center; line-height:30px; background:#AED4F5; height: 30px; width: 32px; cursor: hand; cursor: pointer; border-radius: 0 5px 5px 0;"><img src="../resource/images/map/search_button.png" height="30" width="30" title="搜索地点" /></div>
							
							<div style="clear:both;"></div>
						</div>
<!-- --------------------------------------------------------------------------------------------------- -->
	   </div>
	   	
       <div id="map_container" style="width: 100%;height: 100%; float: left;">
       </div>


<%-- javascript 区域 --%>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.1&key=8e224a5f1ea5161ede7d4d8da4f1cca0"></script>
<script type="text/javascript">
//
//---------------------------------------- 全局变量 ------------------------------------------------
//
  var partMapAreaMethod_selectArticleImplementation = function() { alert("partMapAreaMethod_selectArticleImplementation is not registered"); };
  var partMapAreaMethod_registerCallbackWhenArticleSelected = function() { alert("partMapAreaMethod_registerCallbackWhenArticleSelected is not registered"); };
  var partMapAreaMethod_registerGetArticleSearchScope = function() { alert("partMapAreaMethod_registerGetArticleSearchScope is not registered"); };
  
	<%
		String methodName_selectArticleImplementation = request.getParameter("methodName_selectArticleImplementation");
		String methodName_registerCallbackWhenArticleSelected = request.getParameter("methodName_registerCallbackWhenArticleSelected");
		String methodName_registerGetArticleSearchScope = request.getParameter("methodName_registerGetArticleSearchScope");
		
		if (methodName_selectArticleImplementation != null) {
	%>
			partMapAreaMethod_selectArticleImplementation = <%= methodName_selectArticleImplementation %>;
	<%
		}

		if (methodName_registerCallbackWhenArticleSelected != null) {
	%>
			partMapAreaMethod_registerCallbackWhenArticleSelected = <%= methodName_registerCallbackWhenArticleSelected %>;
	<%
		}
		
		if (methodName_registerGetArticleSearchScope != null) {
	%>
			partMapAreaMethod_registerGetArticleSearchScope = <%= methodName_registerGetArticleSearchScope %>;
	<%		
		}
	%>
	
	var partMapAreaVar_mapObj;
	var partMapAreaVar_meMarker;
	var partMapAreaVar_userPosition = new AMap.LngLat(105.29296875, 33.79740877);
	var partMapAreaVar_promptMarker;
	var MouseTimer;
</script>

<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/resource/js/map.js"></script>

<script type="text/javascript">

//
//---------------------------------------- 自动执行代码 ------------------------------------------------
//

	// 注册话题列表获取成功后的回调方法
	partMapAreaMethod_registerCallbackWhenArticleSelected(updateWhenArticleSelected);
	
	// 注册获取话题搜索位置范围的回调方法
	partMapAreaMethod_registerGetArticleSearchScope(getArticleSearchScope);
	
	
	$(document).ready(function() {
		initMapContainer();
		//设置浮动层的位置
		setTagPromptPosition();
		setShowAddrPosition();
		setIndexCenterBottomMenuPosion();
		//点击我的位置事件
		$("#myAddr").click(function(){
			//清除该提示marker
			removeMarker(partMapAreaVar_promptMarker);
			partMapAreaVar_mapObj.setCenter(partMapAreaVar_meMarker.position);
		});
		//设置菜单的鼠标事件和点击事件
		$(".menu-Items-ItemImg").mouseover(function(){
			var evenNode = this;
			MouseTimer = setTimeout(function(){
				bottomMenuItemMouseOver(evenNode);
			}, 300);
		});
		$(".menu-Items-ItemImg").mouseout(function(){
			var evenNode = this;
			if (MouseTimer){
				clearTimeout(MouseTimer);
				bottomMenuItemMouseOut(evenNode);
			}
		});
		/* $(".menu-Items-ItemImg").hoverIntent({over:bottomMenuItemMouseOver, interval:30, out:bottomMenuItemMouseOut}); */
		$(".menu-Items-ItemImg").click(function(){
			/* $(this).animate({'-moz-opacity':'0.5', 'opacity':'0.5', 'filter':'alpha(opacity=50)', 'width': 48, 'height':48}, 'fast'); */
			$(this).animate({'width': 48, 'height':48}, 'fast');
		});
		//加载点击更多标签时的事件
		$(".tagPrompt").click(function(){
			$(this).fadeOut(2);
			//addNewTags();
		});
		$(window).resize(function(){
			setTagPromptPosition();
			setShowAddrPosition();
			setIndexCenterBottomMenuPosion();
		});
		//搜索框输入字符时的效果及提示
		$("#searchKeywords").keyup(searchPrompt);
		//取消搜索是的效果
		$("#search-cancel").click(cancelSearch);
		//点击搜索
		$("#search-btn").click(keywordSearch);
	});
	
//
//---------------------------------------- 对外公开的函数 ------------------------------------------------
//

	function partMapAreaMethod_getCurrentUserPositionInfo() {
		
		var mapX = $('#mapX').val();
		var mapY = $('#mapY').val();
		var mapAddr = $('.mapAddr').html();
		var mapProvider = $('#mapProvider').val();

		var posiInfoArray = [mapX, mapY, mapAddr, mapProvider];
		return posiInfoArray;
	}

//
//---------------------------------------- 私有函数 ------------------------------------------------
//

	<% 
		UserinfoDto userInfoDto = (UserinfoDto)session.getAttribute(SystemConstants.LOGINUSER_SESSION_NAME); 
		String ipCity = (String) session.getAttribute(SystemConstants.LOGINUSER_SESSION_IPCITY);
	%>
	//初始化地理位置选择框
	function initMapContainer() {
        
		// 创建地图实例  
        partMapAreaVar_mapObj = new AMap.Map("map_container", {
        	level: 16, //地图初始化时的视野级别
        	//center: partMapAreaVar_userPosition, //地图初始化时的中心点经纬度坐标
        	zooms : [3,18], //地图视野级别范围，如：[3,19]，3 为最小级别，19 为最大级别
        	dragEnable : true, //定义地图是否可以拖拽
        	zoomEnable : true, //定义地图视野级别是否可以更改
        	keyboardEnable : true, //定义地图是否可以被键盘控制
        	jogEnable: true, //定义地图拖拽时是否支持缓动效果
        	continuousZoomEnable: true, //定义地图是否有连续缩放效果
        	doubleClickZoom : false, //定义地图是否可以双击放大
        	scrollWheel: false //定义地图是否支持鼠标滚轮缩放
        });
		// 加载工具条  
        partMapAreaVar_mapObj.plugin(["AMap.ToolBar","AMap.OverView,AMap.Scale"], function() {  
			tool = new AMap.ToolBar({
				direction: true, // 方向导航
				ruler: true, // 视野级别控制尺
				autoPosition: false, // 禁止自动定位  
				offset: {x: -10, y: 3}
			});
			partMapAreaVar_mapObj.addControl(tool);
//				加载比例尺
			scale = new AMap.Scale();
			partMapAreaVar_mapObj.addControl(scale); 
		});

		// 设置地图显示位置
        	var ipCity = new String('<%= ipCity == null ? "" : ipCity%>');
        	
            if (ipCity != "" && (ipCity.indexOf("全国") == -1)) {
            	if(ipCity.indexOf('市') == -1){
            		ipCity = ipCity +'市';
            	}
            	
            	partMapAreaVar_mapObj.setCity(ipCity, function(){
            		partMapAreaVar_userPosition = partMapAreaVar_mapObj.getCenter();
            		createMeMarker();
            		getPositionInfo(partMapAreaVar_userPosition);
                    partMapAreaMethod_selectArticleImplementation();
            	});
            } else {
            	partMapAreaVar_mapObj.setZoom(4);
            	partMapAreaVar_mapObj.setCenter(partMapAreaVar_userPosition);
            	createMeMarker();
        		getPositionInfo(partMapAreaVar_userPosition);
            	partMapAreaMethod_selectArticleImplementation();
            }
      
      //绑定地图的右键单击事件
        partMapAreaVar_mapObj.bind(partMapAreaVar_mapObj, "rightclick", function(e){
        	//右键点击不触发moveCenterPrompt()
			removeMarker(partMapAreaVar_promptMarker);
			
        	loadRightClickMenu(partMapAreaVar_mapObj, e.lnglat);
        });
		
		//绑定鼠标左键双击事件,添加单击事件后双击事件失去作用
		partMapAreaVar_mapObj.bind(partMapAreaVar_mapObj,"dblclick",function(e){
			moveCenterPrompt(e.lnglat);
		});
		
		// 绑定地图范围变化事件
		partMapAreaVar_mapObj.bind(partMapAreaVar_mapObj, "zoomchange", function(e){
			// 如果用户已经在地图中心，则更新文章
			if (partMapAreaVar_mapObj.getCenter() && partMapAreaVar_mapObj.getCenter().lng == partMapAreaVar_userPosition.lng && partMapAreaVar_mapObj.getCenter().lat == partMapAreaVar_userPosition.lat) {
				partMapAreaMethod_selectArticleImplementation(); // 获取话题列表
			}
			else {  // 否则，在地图中心显示逛逛提示框
				moveCenterPrompt(partMapAreaVar_mapObj.getCenter() );
			}
		});

		// 绑定地图拖拽变化事件
		partMapAreaVar_mapObj.bind(partMapAreaVar_mapObj, "dragend", function(e){
			moveCenterPrompt(partMapAreaVar_mapObj.getCenter() );
		});

        
//		userWalkOnMap(partMapAreaVar_meMarker, partMapAreaVar_userPosition, partMapAreaVar_mapObj);
	}
	
	function createMeMarker() {
		var meLogoPath = "<%=userInfoDto.getUserHeadImagUrl() %>";
        var conHtmlStr = '<div id="myLocationMarkerContent">'
        					+'<span class="jian_sp1">'  
        					/* +	'<span class="sp2"></span>' */  
        					+'</span>'
        					+'<img src="'+meLogoPath+'" style="width:40px;height:40px;"/>'
        				+'</div>';
		partMapAreaVar_meMarker = new AMap.Marker({  
			id:"myLocation",
			zIndex: 0,
			cursor: 'auto',//鼠标移上去以后显示为指针
			position:partMapAreaVar_userPosition,
			draggable: true, 
			/* content: $("<div class='map_tb'><img src='"+ meLogoPath + "' class='map_tb_img'/></div>").get(0), */
			content: conHtmlStr,
			offset:{x:-23,y:-46}  //偏移量需要根据marker内容大小来设置。无偏移量的情况，是从marker内容（图片）的左上角原点算起。所以一般偏移量是marker内容的-width/2和-height
		});  	
		partMapAreaVar_mapObj.addOverlays(partMapAreaVar_meMarker);
		//？？？点击右键和左键双击不让头像移动？？？
		
		// marker实现拖拽
		partMapAreaVar_mapObj.bind(partMapAreaVar_meMarker,"dragstart",function(e){
			partMapAreaVar_userPosition = partMapAreaVar_meMarker.position;
		});
		
		partMapAreaVar_mapObj.bind(partMapAreaVar_meMarker,"dragend",function(e){
			moveCenterPrompt(e.lnglat);
		});

		//我的头像右键事件
		partMapAreaVar_mapObj.bind(partMapAreaVar_meMarker, "rightclick", function(e){
			var pixelX = e.clientX + 15;
			var pixelY = e.clientY - 35;
			if (partMapAreaVar_promptMarker) {
				partMapAreaVar_mapObj.removeOverlays(partMapAreaVar_promptMarker);
			}
			
			partMapAreaVar_meMarkerRightClickMenu(pixelX, pixelY);
		});
		
	}

	/*
	 * @author:zcw
	 * 在自己头像上点击右键的菜单方法
	**/
	function partMapAreaVar_meMarkerRightClickMenu(pixelX, pixelY){
		var positionLng = partMapAreaVar_userPosition.lng;
		var positionLat = partMapAreaVar_userPosition.lat;
		rightClickMenu = new AMap.ContextMenu();
		rightClickMenu.addItem("我的个人信息", function(e){
			window.open('<%=request.getContextPath() %>' + "/user/userInfoModifiy" , "_blank");
		}, 0);
		rightClickMenu.addItem("收藏当前位置", function(e){
			$.ajax({
				url:'<%=request.getContextPath()%>/user/ajaxAddFavorPosi',
				data:{
				 'mapX': positionLng,
				 'mapY': positionLat,
				 'mapAddr': $('.mapAddr').html(),
				 'mapProviderIdProperty': $('#mapProvider').val()
				},
				type:'post',
				async: false,
				dataType:'json',
				success: function(res){
						if(res.result == 0){
							//改进：在提示信息框中集中显示
							alert("当前位置已经成功收藏！");
						}
						else{
							alert("无法收藏当前位置！" + res.message);
						}
					} 
			});
		}, 1);
		rightClickMenu.addItem("发表新话题", function(e){
			//partCreateArticleMethod_showCreationDiv();
			xianshibiaoqian('addArticle');
		}, 2);
		//根据指定位置(partMapAreaVar_userPosition)在地图上显示菜单
		var pixel = new AMap.Pixel(pixelX, pixelY);
		var position = partMapAreaVar_mapObj.containTolnglat(pixel);
		rightClickMenu.open(partMapAreaVar_mapObj, position);
	}

	function getPositionInfo(lnglatXY) {
		// 查询用户位置信息
		var geo = new AMap.Geocoder({ 
			range:100,//范围 
			crossnum:1,//道路交叉口数 
			roadnum :1,//路线记录数 
			poinum:1//POI点数 
		}); 
		geo.regeocode(lnglatXY,function(data){  
	        var resultStr="无相关位置信息";  
	        if(data.status =="E0") {  
	            if (data.list.length > 0) {
	                resultStr = data.list[0].province.name+data.list[0].city.name+data.list[0].district.name;

	                var address = '';
	                var place = '';
                    
                    if (data.list[0].poilist.length > 0){
                        if (data.list[0].poilist[0].address != '' || data.list[0].poilist[0].address != ' ') {
                        	address = data.list[0].poilist[0].address;
                        }
                        place = data.list[0].poilist[0].name;
                    }

                    if (address == '' && data.list[0].roadlist.length > 0){  
                    	address = data.list[0].roadlist[0].name;  
                    }

                    resultStr+= ' ' + address + ' ' + place; 

                    if (resultStr.length > 22) {
                    	resultStr = data.list[0].district.name + address + ' ' + place;
                    }

                    if (resultStr.length > 22) {
                    	resultStr = place;
                    }
	            }  
	        } else if(data.status =="E1") {  
	             resultStr = "未查找到任何结果！";     
	        } else {  
	             resultStr= "错误信息："+data.state;  
	        }

			// alert("position send back for " + data.list[0].poilist[0].x + ":" + data.list[0].poilist[0].y + ", " + resultStr);
	        $('#map_pos_info').attr("title", "我的位置:"+resultStr);
			$('.mapAddr').html(resultStr);

	        //upload position info
	        var userPosition = partMapAreaMethod_getCurrentUserPositionInfo();  // 返回四个值 mapX, mapY, mapAddr, mapProvider
	    	$.ajax({
	    		type: "post",
	    		url:"../user/ajaxSetPosition",
	    		data: {
	    		       "userMapX" : userPosition[0],
	    		       "userMapY" : userPosition[1],
	    		       "userMapAddr" : userPosition[2],
	    		       "userMapProvider" : userPosition[3]
	    		}, 
	    		dateType: "json",
	    		success: function(res) {
	    			if(res.result != 0) {
	    				alert("系统无法记录当前位置信息！" + res.message);
	    			}
	    		}
	    	});
	    	
	    }); 
	     
        $('#mapX').val(lnglatXY.lng);
        $('#mapY').val(lnglatXY.lat);
        // 输入一个空串'&nbsp;'是为了防止“换个地方”在切换信息时位置发生浮动
        //$('.mapAddr').html('&nbsp;');
	}

	// 获取文章搜索的位置范围
	function getArticleSearchScope() {

		var boundary = partMapAreaVar_mapObj.getBounds();
		// 返回四个值 minX, maxX, minY, maxY
		var scope = new Array(boundary.southwest.lng, boundary.northeast.lng, boundary.southwest.lat, boundary.northeast.lat);
		// alert("Search position scope is: " + scope[0] + "-" + scope[1] + ":" + scope[2] + "-" + scope[3]);
		return scope;
	}
	
	/***************************************************改变位置***********************************************************/
	
	//搜索提示
	function searchPrompt(){
		var keywords = $("#searchKeywords").val();
		if (keywords.length >= 2) {
			$("#search-prompt").parent().css("overflow", "");
			searchPromptByKeyword(keywords);
		}
	}
	
	//搜索需要显示的内容
	function searchPromptByKeyword(keywords){
		//var keywords = $("#searchKeywords").val();
		var city = $("#searchCity").val();
		var PoiSearchOption = {
				srctype:"POI", //数据来源
				type:"", //数据类别
				number:10, //每页数量,默认10
				batch:1, //请求页数，默认1
				range:3000, //查询范围，默认3000米
				ext:""//扩展字段
		};
		var MSearch = new AMap.PoiSearch(PoiSearchOption);
		if (city == '' || city == ' ') {
			city = keywords;
		}
		MSearch.inputPrompt(keywords, city, searchPrompt_CallBack);
	}
	
	function addmarker(i, d) {
        var markerOption = {
            icon:"http://api.amap.com/webapi/static/Images/" + (i + 1) + ".png",
            position:new AMap.LngLat(d.x, d.y)
        };
        var mar = new AMap.Marker(markerOption);
        mar.id = (i + 1);
        partMapAreaVar_mapObj.addOverlays(mar);
        partMapAreaVar_mapObj.bind(mar,"click",function(e){
			moveCenterPrompt(e.lnglat);
		});
    }

	
	function searchPrompt_CallBack(data){
		if (data.status == "E0") {
			$("#search-prompt").html("");
			for (var i = 0; i < data.list.length; i++) {
				var resultStr = "<div style=\"height:20px; line-height:20px; margin: 2px; width:99%; overflow:hidden; text-align:left; cursor: pointer;\" onclick=\"searchPromptClick(this)\" onmouseover=\"searchPromptMouseOver(this)\" onmouseout=\"searchPromptMouseOut(this)\">"+data.list[i]+"</div>";
				$("#search-prompt").append(resultStr);
			}
		}
	}
	
	//点击提示的某一项时
	function searchPromptClick(obj){
		$("#searchKeywords").val($(obj).html());
		keywordSearch();
	}
	
	function searchPromptMouseOver(obj){
		$(obj).css("background", "#AED4F5");
	}
	
	function searchPromptMouseOut(obj){
		$(obj).css("background", "#FFFFFF");
	}
	
	function searchAddr(){
		//让原来部分隐藏搜索部分显示
		$("#map_pos_info").find("span").css("display", "none");
		$("#search-input").css("display", "block");
		//改变右边文章列表的内容
		//$("#indexArticleListDiv").html("<div>sorry id'ont know</div>");
		var city = $(".mapAddr").html();
		city = city.substring((city.indexOf("省") + 1), (city.indexOf("市") + 1));
		$("#searchCity").val(city);
	}
	
	//取消搜索
	function cancelSearch() {
		$("#search-input").css("display", "none");
		$("#map_pos_info").find("span").css("display", "block");
		partMapAreaVar_mapObj.setZoom(16);
		partMapAreaVar_mapObj.setCenter(partMapAreaVar_meMarker.position);
	}
	//按关键字查询
	function keywordSearch() {
		$("#search-btn > img").attr('src', '../resource/images/map/search_btn.gif');
		$("#search-prompt").parent().css("overflow", "hidden");
		var keywords = $("#searchKeywords").val();
		var city = $("#searchCity").val();
		if (keywords == "") {
			keywords = city;
        	if(city.indexOf('市') == -1){
        		city = city +'市';
        	}
			partMapAreaVar_mapObj.setCity(city, function(){
				//partMapAreaVar_meMarker.setPosition(partMapAreaVar_mapObj.getCenter());
				moveCenterPrompt(partMapAreaVar_mapObj.getCenter());
			});
		}
		var PoiSearchOption = {
				srctype:"POI", //数据来源
				type:"", //数据类别
				number:10, //每页数量,默认10
				batch:1, //请求页数，默认1
				range:3000, //查询范围，默认3000米
				ext:""//扩展字段
		};
		var MSearch = new AMap.PoiSearch(PoiSearchOption);
		MSearch.byKeywords(keywords, city, keywordSearch_CallBack);
	}
	//查询的回调函数
	function keywordSearch_CallBack(data) {

		var resultStr = "";
		if (data.status == "E0") {
			resultCount = data.list.length;
			partMapAreaVar_mapObj.clearOverlays();
			for (var i = 0; i < data.list.length; i++) {
				resultStr += 
					"<div style=\"font-size: 12px; cursor:pointer; border-bottom:1px solid #00668F; margin:3px;\" onclick=\"gotoSearchAddr("+data.list[i].x+", "+data.list[i].y+")\" onmouseover=\"searchPromptMouseOver(this)\" onmouseout=\"searchPromptMouseOut(this)\">"
					+	"<table>"
					+		"<tr><td>"
					+			"<img src=\"http://api.amap.com/webapi/static/Images/" + (i + 1) + ".png\"></td>" 
					+ 			"<td><font color=\"#00a6ac\"><b>名称: " + data.list[i].name + "</b></font><br/>";
				resultStr += 
					TipContents(data.list[i].type, data.list[i].address, data.list[i].tel) 
					+ 		"</td></tr>"
					+	"</table>"
					+"</div>";
					
				addmarker(i, data.list[i]);
			}
			if ($("#searchKeywords").val() != "") {
				partMapAreaVar_mapObj.setFitView();
				removeMarker(partMapAreaVar_promptMarker);
			} else {
				moveCenterPrompt(partMapAreaVar_mapObj.getCenter());
			}
		} else if (data.status == "E1") {
			resultStr = "未查找到任何结果!<br />建议：<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";
		} else {
			resultStr = "服务器繁忙,请稍后再试";
		}
		$("#indexArticleListDiv").html(resultStr);
		
		$("#search-btn > img").attr('src', '../resource/images/map/search_button.png');
		var indexArticleListDivHeight = $('#indexArticleListDiv').height();
		$('#indexArticleListDiv').height(indexArticleListDivHeight);
		$('.scroll-pane').jScrollPane();
	}
	//回调函数中改变部分数据
	function TipContents(type, address, tel) {
		
		if (type == "" || type == "undefined" || type == null || type == " undefined" || typeof type == "undefined") {
			type = "暂无";
		}
		
		if (address == "" || address == "undefined" || address == null || address == " undefined" || typeof address == "undefined") {
			address = "暂无";
		}
		
		if (tel == "" || tel == "undefined" || tel == null || tel == " undefined" || typeof address == "tel") {
			tel = "暂无";
		}
		
		var str = "&nbsp;&nbsp;地址：" + address + "<br />&nbsp;&nbsp;电话：" + tel + " <br />&nbsp;&nbsp;类型：" + type;
		
		return str;
	}
	//移动到指定搜索地点
	function gotoSearchAddr(lng, lat) {
		var position = new AMap.LngLat(lng, lat);
		moveCenterPrompt(position);
		//设置地图中心在这儿
		partMapAreaVar_mapObj.setCenter(position);
	}
</script>